#include "SockData.h"
#include "Socket.h"
#include "../../algorithm/Algorithm.h"

DEF_BEG_LIBTOOLS

std::list<SocketData*>::iterator GetWaitAccepts(SocketData& svrSock, OVERLAPPED_EX* o)
{
	std::list<SocketData*>::iterator it = svrSock._pServerBuf->waitAccepts.end();
	for (it = svrSock._pServerBuf->waitAccepts.begin(); it != svrSock._pServerBuf->waitAccepts.end(); ++it)
	{
		if (o == (*it)->_pServerBuf->oved.Get())
		{
			break;
		}
	}

	return it;
}

bool EmptyWaitAccepts(SocketData& svrSock)
{
	return svrSock._pServerBuf->waitAccepts.empty();
}

bool IsWaitAcceptsEnd(SocketData& svrSock, const std::list<SocketData*>::iterator& it)
{
	return svrSock._pServerBuf->waitAccepts.end() == it;
}

void PushWaitAccepts(SocketData& svrSock, SocketData& cliSock)
{
	svrSock._pServerBuf->waitAccepts.push_back(&cliSock);
}

void EraseWaitAccepts(SocketData& svrSock, const std::list<SocketData *>::iterator& it)
{
	svrSock._pServerBuf->waitAccepts.erase(it);
}

void EraseWaitAccepts(SocketData& svrSock, SocketData& cliSock)
{
	seq_erase(svrSock._pServerBuf->waitAccepts, &cliSock);
}

DEF_END_LIBTOOLS